
[dbo].[asi_DocumentInheritLicenseRestrictions]
CREATE PROCEDURE dbo.asi_DocumentInheritLicenseRestrictions
(@documentVersionKey uniqueidentifier,
@parentHierarchyKey uniqueidentifier = '00000000-0000-0000-0000-000000000000')
AS
BEGIN
DECLARE @parentDocumentVersionKey uniqueidentifier
IF @parentHierarchyKey = '00000000-0000-0000-0000-000000000000'
BEGIN
SELECT @parentDocumentVersionKey = parent.[UniformKey]
FROM [dbo].[Hierarchy] parent INNER JOIN [dbo].[Hierarchy] child ON parent.[HierarchyKey] = child.[ParentHierarchyKey]
WHERE child.[UniformKey] = @documentVersionKey
END
ELSE
BEGIN
SELECT @parentDocumentVersionKey = [Hierarchy].[UniformKey]
FROM [dbo].[Hierarchy]
WHERE [Hierarchy].[HierarchyKey] = @parentHierarchyKey
END
INSERT INTO [dbo].[UniformLicense] ([LicenseKey], [UniformKey])
SELECT [UniformLicense].[LicenseKey], @documentVersionKey
FROM [dbo].[UniformLicense]
WHERE [UniformLicense].[UniformKey] = @parentDocumentVersionKey
AND [UniformLicense].[LicenseKey] NOT IN
(SELECT [UniformLicense].[LicenseKey] FROM [dbo].[UniformLicense] WHERE [UniformLicense].[UniformKey] = @documentVersionKey)
END
GO